<%layout("/common/_layout.html"){%>
<%#ajax userTable:{%>
<div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
    <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
    <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">系统管理</strong>
        /
        <small>意见反馈</small>
    </div>
</div>
<form class="am-form" id="list-form" action="${base}/userfeedback/list" method="post">
    <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
    <table class="am-table am-table-bordered am-table-radius table-main">
        <tbody>
            <tr>
                <th class="am-text-middle">反馈类型</th>
                <td>
                    <div class="am-u-sm-12">
                        <select data-am-selected="{btnWidth: '100%',maxHeight: 200,btnSize:'sm'}" name="type" id="type">
                            <option value="-1"<%if(type=="-1"){%>
                                selected
                                <%}%>>所有</option>
                            <option value="0" <%if(type=="0"){%>
                                selected
                                <%}%>>功能异常</option>
                            <option value="1" <%if(type=="1"){%>
                                selected
                                <%}%>>优化建议</option>
                        </select>
                    </div>
                </td>
                <th class="am-text-middle">处理状态</th>
                <td>
                    <div class="am-u-sm-12">
                        <select data-am-selected="{btnWidth: '100%',maxHeight: 200,btnSize:'sm'}" name="state" id="state">
                            <option value="-1"<%if(state=="-1"){%>
                                selected
                                <%}%>>所有</option>
                            <option value="0" <%if(state=="0"){%>
                                selected
                                <%}%>>未处理</option>
                            <option value="1" <%if(state=="1"){%>
                                selected
                                <%}%>>已处理</option>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <th class="am-text-middle">反馈时间</th>
                <td >
                    <div class="am-u-sm-10">
                        <div class="am-form am-form-inline">
                        <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                            <input type="text" class="am-form-field am-input-sm" id="start_time" value="${start_time!}" placeholder="开始日期" data-am-datepicker readonly></div>
                        <div class="am-form-group">至</div>
                        <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                            <input type="text" class="am-form-field am-input-sm" id="end_time" value="${end_time!}" placeholder="结束日期" data-am-datepicker readonly></div>
                    </div>
                    </div>
                </td>
                <th class="am-text-middle">故障模块</th>
                <td>
                    <div class="am-u-sm-12">
                        <select id="gzmk_options" name="org" data-am-selected="{btnSize: 'sm',maxHeight: 500,searchBox: 1}">
                            <option value="-1"
                            <%if (isEmpty(guzhangCode)||guzhangCode=="-1"){%>
                            selected = "selected"
                            <%}%>
                            >所有</option>
                            <%for(o in gzmk_options!){%>
                            <option value="${o.code}"
                            <%if (!isEmpty(guzhangCode)&&guzhangCode==o.code){%>
                            selected = "selected"
                            <%}%>
                            >${o.name}</option>
                            <%}%>
                        </select>
                    </div>
                </td>

            </tr>

            <tr>

                <td colspan="6">

                     <div align='right'>
                        <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="search-button">
                            <i class="am-icon-search"></i>
                            搜索
                        </button>
                        <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="export-button">
                            <i class="am-icon-download"></i>
                            导出
                        </button>
                    </div>
                </td>               
            </tr>

            
            <tr id="download" style="display:none">
                <td colspan="4">
                    <div align='center'>
                        <a id="downloadlink" href="#">导出成功，点击下载</a>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</form>
<div class="am-g" >
    <div class="am-u-sm-12 am-scrollable-horizontal">
        <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
        <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
                <tr class="am-text-nowrap">
                    <th class="table-title">姓名</th>
                    <th class="table-title">手机号</th>
                    <th class="table-title">地市</th>
                    <th class="table-title">反馈类型</th>
                    <th class="table-title">故障模块</th>
                    <th class="table-date">反馈时间</th>
                    <th class="table-date">反馈内容</th>
                    <th class="table-date">状态</th>
                    <th class="table-set am-text-center">操作</th>
                </tr>
            </thead>
            <tbody>
                <%for(list in pager.list!){%>
                <tr>
                    <td>${list.name}</td>
                    <td>${list.phone}</td>
                    <td>${list.city}</td>
                    <td>${list.type}</td>
                    <td>${list.gzmk}</td>
                    <td>${list.time,dateFormat="yyyy-MM-dd"}</td>
                    <td style="max-width:300px;">${list.content}</td>
                    <td id="process_state">${list.processState}</td>
                    <td>
                        <div class="am-btn-toolbar">
                            <div class="am-btn-group am-btn-group-xs">
                                <%if(list.state==0) {%>
                                <button type="button" id="btnProcess${list.id}" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="processFun(${list.id});">
                                    <span class="am-icon-pencil-square-o"></span>
                                    处理
                                </button>
                                <%}%></div>
                        </div>
                    </td>
                </tr>
                <%}%></tbody>
        </table>

        <div class="am-cf">
            <!-- 分页 -->
            <%if (pager.list.~size >
            0){%>
            <div class="am-fr">
                <% include("/admin/common_pager.tpl"){}%></div>
            <%}else{%>
            <% include("/admin/waiting_hint.tpl"){}%>
            <div class="am-kai">
                <h3>没有找到任何记录!</h3>
            </div>
            <div style="height:200px;"></div>
            <%}%></div>
        <%}%></div>
</div>
<script type="text/javascript">
    var urlBase = "${base}";
    var url;

    $(function(){      
        $("#search-button").on("click",function(){
            if(!checkParams()){
                return;
            }
            setKeyWords();
            showWaitingHint("正在查询，请稍候...");
            $("#list-form").submit();
        });

        $("#export-button").on("click",function(){
            if(!checkParams()){
                return;
            }
            $('#download').hide();
            //loading层
            var index = parent.layer.load(0, {
              shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            setKeyWords();          
            var formParam = $("#list-form").serialize();//序列化表格内容为字符串  
            $.ajax({  
                type:'post',      
                url:'${base}/userfeedback/export',  
                data:formParam,  
                success:function(data){              
                   console.log(data);
                   if(data.status==1){
                     $('#downloadlink').text(data.message);
                     $('#downloadlink').attr('href',data.url);
                     $('#download').show();
                  }else{
                     $('#downloadlink').text(data.message);
                     $('#download').show();
                  }
                  parent.layer.close(index);
                },
                error: function() { 
                   parent.layer.close(index);
                } 
            }); 
        });
    });  
    function setKeyWords(){
        var keywordsObj = {};
        keywordsObj.start_time = $("#start_time").val();
        keywordsObj.end_time = $("#end_time").val();


        if($("#gzmk_options").val() != "-1"){
            keywordsObj.gzmk_option = $("#gzmk_options").val();
        }
        if($("#type").val() != "-1"){
            keywordsObj.type = $("#type").val();    
        }
        if( $("#state").val() != "-1"){
            keywordsObj.state = $("#state").val();
        }         

        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
            keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);
        $("#keywords").val(keywords);
    }

    function checkParams(){
        var startDate = new Date($("#start_time").val());
        var endDate = new Date($("#end_time").val());
        if(startDate>endDate){
            alert("开始时间不能大于结束时间，请重新输入！");
            return false;
        }
        return true;
    }

    var processFun = function(id) {   
        var $processBtn = $("#btnProcess"+id);// 删除按钮
        if (confirm('您确定将该记录的状态修改为"已处理"吗？') == true) {       
            $.ajax({
                url : urlBase+'/userfeedback/updateState?id='+id,
                dataType : "json",
                async : false,
                beforeSend : function(data) {
                    $processBtn.prop("disabled", true)
                },
                success : function(data) {                
                    if (data.status == "success") {
                        $processBtn.parent().parent().parent().parent().find('#process_state').html('已处理');
                        $processBtn.remove();
                    }
                    sendMessage({
                        title : '更新',
                        text : data.message,
                        type : "success",
                        timer : 2000,
                        showConfirmButton : false
                    });               
                }
            });
        }
    }
</script>
<%}%>